home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-03 | 5.7 KB | 275 lines | [TEXT/KAHL] |
- // Contains utilities, add this and SoundByte.c to a project
- // along with MacTraps lib in Think C or compiled with the
- // usual C libraries in MPW. This has not been compiled
- // under MPW but you should have very little problems if any
- // doing so.
-
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <Traps.h>
- #include <GestaltEqu.h>
- #include <AppleEvents.h>
- #include <Sound.h>
-
- #include "OCEErrors.h"
- #include "DigitalSignature.h"
-
- #include "SoundByte.h"
- #include "SoundByteUtils.h"
-
- extern Environment gEnvironment;
-
- void BasicInitializations()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- }
-
- Boolean Prerequisites()
- {
- OSErr error;
- long value;
- Boolean result = false;
-
- do {
- if (NGetTrapAddress(_GestaltDispatch,ToolTrap) == NGetTrapAddress(_Unimplemented,ToolTrap))
- break;
- if (error = Gestalt(gestaltDigitalSignatureVersion, &value))
- break;
- result = true;
- } while (0);
-
- return result;
- }
-
- void InitSoundByteMenus()
- {
- Handle menuBar = GetNewMBar(rMenuBar);
-
- if (menuBar == nil)
- AlertOSErr(ResError());
-
- SetMenuBar(menuBar);
- ReleaseResource(menuBar);
-
- AddResMenu(GetMHandle(mApple), 'DRVR');
- DrawMenuBar();
- }
-
- OSErr GotRequiredAEParams(AppleEvent *event)
- {
- DescType returnedType;
- Size actualSize;
- OSErr error;
-
- error = AEGetAttributePtr(event, keyMissedKeywordAttr, typeWildCard, &returnedType, nil, 0, &actualSize);
- if (error == errAEDescNotFound)
- return noErr;
- else if (error == noErr)
- return errAEEventNotHandled;
- else
- return error;
- }
-
- pascal OSErr DoAEOpenApp(AppleEvent *event, AppleEvent *reply, long refCon)
- {
- #pragma unused (reply, refCon)
- return GotRequiredAEParams(event);
- }
-
- pascal OSErr DoAEQuitApp(AppleEvent *event, AppleEvent *reply, long refCon)
- {
- #pragma unused (reply, refCon)
- return GotRequiredAEParams(event);
- }
-
- pascal OSErr DoAEPrintDoc(AppleEvent *event, AppleEvent *reply, long refCon)
- {
- #pragma unused (reply, refCon)
- return GotRequiredAEParams(event);
- }
-
- pascal OSErr DoAEOpenDoc(AppleEvent *event, AppleEvent *reply, long refCon)
- {
- #pragma unused (reply, refCon)
-
- long index;
- AEDescList docList;
- Size actualSize;
- AEKeyword keyword;
- DescType type;
- FSSpec theFile;
- long count;
- OSErr error;
-
- do {
- if (error = AEGetParamDesc(event, keyDirectObject, typeAEList, &docList)) // get the doc list
- break;
- if (error = GotRequiredAEParams(event))
- break;
- if (error = AECountItems(&docList, &count))
- break;
- for (index=1; index<=count; index++)
- {
- if (error = AEGetNthPtr(&docList, index, typeFSS, &keyword, &type, (Ptr)&theFile, sizeof(FSSpec), &actualSize))
- break;
- }
- } while (0);
-
- AEDisposeDesc(&docList);
-
- AlertOSErr(error);
-
- return error;
- }
-
- void InitAppleEvents()
- {
- OSErr error;
-
- do {
- if (error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, (EventHandlerProcPtr)DoAEOpenApp, 0, false))
- break;
- if (error = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, (EventHandlerProcPtr)DoAEOpenDoc, 0, false))
- break;
- if (error = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, (EventHandlerProcPtr)DoAEPrintDoc, 0, false))
- break;
- if (error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, (EventHandlerProcPtr)DoAEQuitApp, 0, false))
- break;
- } while (0);
-
- AlertOSErr(error);
- }
-
- void ApplicationStartup()
- {
- long soundAttrs;
-
- Gestalt(gestaltSoundAttr, &soundAttrs);
-
- gEnvironment.hasSoundInput = (soundAttrs & gestaltHasSoundInputDevice);
- gEnvironment.running = true;
- gEnvironment.inBackground = false;
- gEnvironment.statusDialog = nil;
-
- InitSoundByteMenus();
- InitAppleEvents();
- }
-
- Handle GetTempHandle()
- {
- OSErr ignore;
- Size max;
- Size canFree = MFFreeMem();
-
- max = MFMaxMem(&canFree) / 2; // don't be too greedy
- return TempNewHandle(max, &ignore);
- }
-
- pascal Boolean AboutFilter(DialogPtr dialog, EventRecord *event, short *item)
- {
- Handle aboutSound;
-
- if (event->what == updateEvt)
- {
- DrawDialog(dialog);
- aboutSound = Get1NamedResource('snd ', "\pPablo's Bass");
- if (aboutSound)
- {
- SetCursor(*GetCursor(watchCursor));
- SndPlay(nil, aboutSound, false);
- SetCursor(&qd.arrow);
- }
- }
-
- return false;
- }
-
- void DoAbout()
- {
- short ignore;
- DialogPtr dialog = GetNewDialog(rSoundByteAboutDialog, nil, kMoveToFront);
-
- ModalDialog(AboutFilter, &ignore);
-
- DisposeDialog(dialog);
- }
-
- void DisplayUserAlert(short messageID, Boolean exitToShell, OSErr error)
- {
- short itemHit;
- Str255 message;
- Str255 errorString;
-
- if (error != noErr) // just a notification really
- NumToString(error, errorString);
- else
- errorString[0] = 0;
-
- GetIndString(message, rMessages, messageID);
- ParamText(message, errorString, kNullPString, kNullPString);
-
- SysBeep(1);
- itemHit = NoteAlert(rSimpleAlert, nil);
-
- if (exitToShell)
- ExitToShell();
- }
-
- void AlertOSErr(OSErr error)
- {
- Boolean bail = true;
- short messageID = kGenericError;
-
- switch (error)
- {
- case noErr:
- case userCanceledErr:
- return;
- case memFullErr:
- messageID = kNoMemory;
- break;
- case paramErr:
- messageID = kBadParam;
- break;
- case errAECoercionFail:
- case errAENotAEDesc:
- case errAEDescNotFound:
- messageID = kAppleEvents;
- break;
- case resNotFound:
- messageID = kNeededResourceMissing;
- break;
- case kSIGVerifyFailedErr:
- bail = false;
- messageID = kVerifyFailed;
- break;
- case kSIGPasswordErr:
- bail = false;
- messageID = kPasswordFailed;
- break;
- case kSIGSignerErr:
- bail = false;
- messageID = kSignerProblem;
- break;
- case kSIGSignerNotValidErr:
- bail = false;
- messageID = kSignerNotValid;
- break;
- }
-
- DisplayUserAlert(messageID, bail, error);
- }
-
-